import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
// import { MatSnackBar } from '@angular/material';
import { UtilService } from '../../my-service/util.service'
declare var $: any;
declare var echarts: any;
@Component({
    selector: 'data-root',
    templateUrl: './data.component.html',
    styleUrls: ['./data.component.css']
})
export class dataComponent {
    data;
    chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
    chnUnitSection = ["", "万", "亿", "万亿", "亿亿"];
    chnUnitChar = ["", "十", "百", "千"];
    
    @Output() onCloseCharts = new EventEmitter<Event>();
    constructor(private UtilService: UtilService) { 
    }
    CloseCharts() {
        this.onCloseCharts.emit()
    }
    Record(data) {
        this.data = data;
        let _html = '';
        
        _html += `<h1 class='title' style="color: #999;font-weight: bold;margin-bottom: 20px;">${data.name}</h1>`
        for (var i = 0; i < data.children.length; i++) {
            _html += `<div class='Record' style="color: #999; padding: 20px;font-weight: bold;border-top: 1px dashed;"><div style="text-align: left;font-size:18px">${data.children[i].name}</div>`;
            for (var j = 0; j < data.children[i].children.length; j++) {
                _html += `<div style="text-align: left;padding-left:6%;">${this.SectionToChinese(j + 1)}、${data.children[i].children[j].name}</div>`;
            }
            _html += `</div>`
        }
        $('#container2').html(_html)
    }
    SectionToChinese(section) {
        let strIns = '', chnStr = '';
        let unitPos = 0;
        let zero = true;
        while (section > 0) {
            let v = section % 10;
            if (v === 0) {
                if (!zero) {
                    zero = true;
                    chnStr = this.chnNumChar[v] + chnStr;
                }
            } else {
                zero = false;
                strIns = this.chnNumChar[v];
                strIns += this.chnUnitChar[unitPos];
                chnStr = strIns + chnStr;
            }
            unitPos++;
            section = Math.floor(section / 10);
        }
        return chnStr;
    }
    copyUrl2() {
        let _html = '';
        _html += `${this.data.name}\n`
        for (var i = 0; i < this.data.children.length; i++) {
            _html += `${this.data.children[i].name}\n`;
            for (var j = 0; j < this.data.children[i].children.length; j++) {
                _html += `   ${this.SectionToChinese(j + 1)}、${this.data.children[i].children[j].name}\n`;
            }   
        }
        var oInput = document.createElement('textarea');
        oInput.value = _html;
        document.body.appendChild(oInput);
        oInput.select();
        document.execCommand("Copy");
        oInput.className = 'oInput';
        oInput.style.display = 'none';
        this.UtilService.remind('success','复制成功')
        // this.snackBar.open(`复制成功`, '确定', {
        //     duration: 2000,
        //     verticalPosition: 'top'
        //   });
    }
}
